<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>下游客户管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">
		var validateForm;
		var $table; // 父页面table表格id
		var $topIndex;//弹出窗口的 index
		function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $table = table;
			  $topIndex = index;
			  jp.loading();
			  $("#inputForm").submit();
			  return true;
		  }

		  return false;
		}

		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					jp.post("${ctx}/infor/lnCustomers/save",$('#inputForm').serialize(),function(data){
						if(data.success){
	                    	jp.success(data.msg);
	                    	jp.close($topIndex);//关闭dialog

	                    }else{
            	  			jp.error(data.msg);
	                    }
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
		});
		
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="lnCustomers" action="${ctx}/infor/lnCustomers/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<table class="table table-bordered">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right">项目：</label></td>
					<td class="width-35">
						<sys:gridselect url="${ctx}/infor/project/data" id="project" name="project.id" value="${lnCustomers.project.id}" labelName="project.name" labelValue="${lnCustomers.project.name}"
							 title="选择项目" cssClass="form-control required" fieldLabels="名称" fieldKeys="name" searchLabels="名称" searchKeys="name" ></sys:gridselect>
					</td>
					<td class="width-15 active"><label class="pull-right">一级客户名称：</label></td>
					<td class="width-35">
						<form:input path="name" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">收货单位名称：</label></td>
					<td class="width-35">
						<form:input path="company" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">收货单位地址：</label></td>
					<td class="width-35">
						<form:input path="address" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">负责人：</label></td>
					<td class="width-35">
						<form:input path="person" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">负责人电话：</label></td>
					<td class="width-35">
						<form:input path="phone" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">客户类型：</label></td>
					<td class="width-35">
						<form:select path="remarks" class="form-control ">
							<form:options items="${fns:getDictList('khType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"></td>
		   			<td class="width-35" ></td>
		  		</tr>
		 	</tbody>
		</table>
		<div class="tabs-container">
            <ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-2" aria-expanded="true">收货地址：</a>
                </li>
				<li class=""><a data-toggle="tab" href="#tab-1" aria-expanded="false">下游客户物料上调比例表：</a>
                </li>
            </ul>
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade ">
			<a class="btn btn-white btn-sm" onclick="addRow('#customerGoodsControrList', customerGoodsControrRowIdx, customerGoodsControrTpl);customerGoodsControrRowIdx = customerGoodsControrRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th>物料</th>
						<th>起始时间</th>
						<th>截止时间</th>
						<th>上浮比例</th>
						<th>附加</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="customerGoodsControrList">
				</tbody>
			</table>
			<script type="text/template" id="customerGoodsControrTpl">//<!--
				<tr id="customerGoodsControrList{{idx}}">
					<td class="hide">
						<input id="customerGoodsControrList{{idx}}_id" name="customerGoodsControrList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="customerGoodsControrList{{idx}}_delFlag" name="customerGoodsControrList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
					<sys:gridselect url="${ctx}/infor/goods/data" id="goods" name="customerGoodsControrList[{{idx}}].goods.id" value="{{row.goods.id}}" labelName="customerGoodsControrList[{{idx}}].goods.name" labelValue="{{row.goods.name}}"
							 title="选择物料" cssClass="form-control required" fieldLabels="名称" fieldKeys="name" searchLabels="物料编码" searchKeys="code" />
						<%--<input id="customerGoodsControrList{{idx}}_goods" name="customerGoodsControrList[{{idx}}].goods.id" type="text" value="{{row.goods.id}}"    class="form-control "/>--%>
					</td>
					
					
					<td>
						<div class='input-group form_datetime' id="customerGoodsControrList{{idx}}_min">
		                    <input type='text'  name="customerGoodsControrList[{{idx}}].min" class="form-control "  value="{{row.min}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>						            
					</td>
					
					
					<td>
						<div class='input-group form_datetime' id="customerGoodsControrList{{idx}}_max">
		                    <input type='text'  name="customerGoodsControrList[{{idx}}].max" class="form-control "  value="{{row.max}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>						            
					</td>
					
					
					<td>
						<input id="customerGoodsControrList{{idx}}_sorft" name="customerGoodsControrList[{{idx}}].sorft" type="text" value="{{row.sorft}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="customerGoodsControrList{{idx}}_num" name="customerGoodsControrList[{{idx}}].num" type="text" value="{{row.num}}"    class="form-control "/>
					</td>
					
					

					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#customerGoodsControrList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var customerGoodsControrRowIdx = 0, customerGoodsControrTpl = $("#customerGoodsControrTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(lnCustomers.customerGoodsControrList)};
					for (var i=0; i<data.length; i++){
						addRow('#customerGoodsControrList', customerGoodsControrRowIdx, customerGoodsControrTpl, data[i]);
						customerGoodsControrRowIdx = customerGoodsControrRowIdx + 1;
					}
				});
			</script>
			</div>
				<div id="tab-2" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#reAddressList', reAddressRowIdx, reAddressTpl);reAddressRowIdx = reAddressRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th>收货详细地址</th>
						<th>到站省</th>
						<th>到站市</th>
						<th>结算地</th>
						<th>运输线路</th>
						<th>线路绩效运价</th>
						<th>合同里程</th>
						<th>收货确认人</th>
						<th>确认人电话</th>
						<th>客户特殊需求</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="reAddressList">
				</tbody>
			</table>
			<script type="text/template" id="reAddressTpl">//<!--
				<tr id="reAddressList{{idx}}">
					<td class="hide">
						<input id="reAddressList{{idx}}_id" name="reAddressList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="reAddressList{{idx}}_delFlag" name="reAddressList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
						<input id="reAddressList{{idx}}_address" name="reAddressList[{{idx}}].address" type="text" value="{{row.address}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_province" name="reAddressList[{{idx}}].province" type="text" value="{{row.province}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_city" name="reAddressList[{{idx}}].city" type="text" value="{{row.city}}"    class="form-control "/>
					</td>
					<td>
					<sys:gridselect    url="${ctx}/infor/settlement/data" id="reAddressList{{idx}}_arrive" name="reAddressList[{{idx}}].arrive.id" value="{{row.arrive.id}}" labelName="reAddressList{{idx}}_arrive.name" labelValue="{{row.arrive.name}}"
							 title="选择结算地" cssClass="form-control required" fieldLabels="名称" fieldKeys="name" searchLabels="结算地" searchKeys="name"  ></sys:gridselect>
					</td>
					
					<td>
						<input id="reAddressList{{idx}}_line" name="reAddressList[{{idx}}].line" type="text" value="{{row.line}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_freight" name="reAddressList[{{idx}}].freight" type="text" value="{{row.freight}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_mileage " name="reAddressList[{{idx}}].mileage " type="text" value="{{row.mileage }}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_person" name="reAddressList[{{idx}}].person" type="text" value="{{row.person}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_phone" name="reAddressList[{{idx}}].phone" type="text" value="{{row.phone}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_needs" name="reAddressList[{{idx}}].needs" type="text" value="{{row.needs}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="reAddressList{{idx}}_remarks" name="reAddressList[{{idx}}].remarks" value="{{row.remarks}}"   class="form-control ">
					</td>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#reAddressList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var reAddressRowIdx = 0, reAddressTpl = $("#reAddressTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(lnCustomers.reAddressList)};
					for (var i=0; i<data.length; i++){
						addRow('#reAddressList', reAddressRowIdx, reAddressTpl, data[i]);
						reAddressRowIdx = reAddressRowIdx + 1;
					}
				});
			</script>
			</div>
		</div>
		</div>
		</form:form>
</body>
</html>